package com.yue.yadmin.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class DateUtils {
	private final static String DATE_STR1 = "yyyy-MM-dd HH:mm:ss";
	
	
	public static String getDateStr(Object obj) throws ParseException{
		return getDateStr(getDate(obj,DATE_STR1),DATE_STR1);
	}
	
	private static Date getDate(Object obj,String pattern) throws ParseException{
		if(obj==null)return new Date();
		String source = String.valueOf(obj);
		if(obj instanceof Long)return new Date(Long.parseLong(source));
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.parse(source);
	}
	
	private static String getDateStr(Date date,String pattern){
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.format(date);
	}
}
